package com.gp.study.tomcat.utils;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import com.gp.study.tomcat.bean.GpServletRegistry;
import com.gp.study.tomcat.http.GPHttpServletRequest;
import com.gp.study.tomcat.http.GPHttpServletResponse;

public class GPIOUtils {
	
	public static String getInputStremContent(InputStream input)throws Exception{
//		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(input));
//		StringBuilder sBuilder = new StringBuilder();
//		String temp = null;
//		while((temp = bufferedReader.readLine())!=null){
//			sBuilder.append(temp);
//		}
//		return sBuilder.toString();
		byte[] reqByte = new byte[1024];
		input.read(reqByte);
		return new String(reqByte);
	}
	
    public static GPHttpServletRequest getServletRequest(String reqStr)throws Exception{
		
    	/**
		 * GET /hello.do HTTP/1.1
			Host: localhost:8990
			Connection: keep-alive
					 */
		//按行拆分
		String[] contents = reqStr.split("\r\n");
		String[] data = contents[0].split(" ");
		GPHttpServletRequest request = new GPHttpServletRequest();
		request.setMethod(data[0]);
		request.setURL(data[1]);
		return request;
	}
    
    public static GPHttpServletResponse getServletResponse()throws Exception{
    	
    	return null;
    }

}
